package com.exam.config;

import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class CacheSerializer {
    @Bean
    public RedisCacheManagerBuilderCustomizer builderCustomizer(){
        return builder -> builder.cacheDefaults(
                RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(
                        RedisSerializationContext.SerializationPair.fromSerializer(
                                RedisSerializer.json()
                        )
                )
//                        指定默认缓存过期时间为1小时
//                        .entryTtl(Duration.ofHours(1L))
        );
    }
}
